package com.grass.p019lv.novel.activity;

import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.SpUtils;
import com.grass.p019lv.databinding.ActivitySearchNovelResultBinding;
import com.grass.p019lv.event.SearchNovelNumEvent;
import com.grass.p019lv.event.SearchVoiceNovelNumEvent;
import com.grass.p019lv.novel.fragment.SearchNovelFragment;
import com.grass.p019lv.novel.fragment.SearchVoiceNovelFragment;
import com.gyf.immersionbar.ImmersionBar;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/* renamed from: com.grass.lv.novel.activity.SearchNovelResultActivity */
public class SearchNovelResultActivity extends BaseActivity<ActivitySearchNovelResultBinding> implements View.OnClickListener {
    public int page;
    SearchNovelFragment searchNovelFragment;
    public String searchTxt;
    SearchVoiceNovelFragment searchVoiceNovelFragment;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return R.layout.activity_search_novel_result;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        EventBus.getDefault().register(this);
        ((ActivitySearchNovelResultBinding) this.binding).tvSearch.setText(this.searchTxt);
        ((ActivitySearchNovelResultBinding) this.binding).tvNovel.setOnClickListener(this);
        ((ActivitySearchNovelResultBinding) this.binding).tvVoiceNovel.setOnClickListener(this);
        ((ActivitySearchNovelResultBinding) this.binding).tvCancel.setOnClickListener(this);
        ((ActivitySearchNovelResultBinding) this.binding).tvSearch.setOnClickListener(this);
        ((ActivitySearchNovelResultBinding) this.binding).imgBack.setOnClickListener(this);
        ((ActivitySearchNovelResultBinding) this.binding).viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            /* class com.grass.p019lv.novel.activity.SearchNovelResultActivity.C31041 */

            @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
            public void onPageScrollStateChanged(int i) {
            }

            @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
            public void onPageScrolled(int i, float f, int i2) {
            }

            @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
            public void onPageSelected(int i) {
                if (i == 0) {
                    SearchNovelResultActivity searchNovelResultActivity = SearchNovelResultActivity.this;
                    searchNovelResultActivity.onClick(((ActivitySearchNovelResultBinding) searchNovelResultActivity.binding).tvNovel);
                    return;
                }
                SearchNovelResultActivity searchNovelResultActivity2 = SearchNovelResultActivity.this;
                searchNovelResultActivity2.onClick(((ActivitySearchNovelResultBinding) searchNovelResultActivity2.binding).tvVoiceNovel);
            }
        });
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initData() {
        super.initData();
        this.searchNovelFragment = SearchNovelFragment.newInstance(this.searchTxt);
        this.searchVoiceNovelFragment = SearchVoiceNovelFragment.newInstance(this.searchTxt);
        ((ActivitySearchNovelResultBinding) this.binding).viewPager.setAdapter(new Adapter(getSupportFragmentManager(), 1));
        ((ActivitySearchNovelResultBinding) this.binding).viewPager.setCurrentItem(this.page);
    }

    public void onClick(View view) {
        if (view.getId() == R.id.tv_novel) {
            ((ActivitySearchNovelResultBinding) this.binding).tvNovel.setTypeface(Typeface.DEFAULT_BOLD);
            ((ActivitySearchNovelResultBinding) this.binding).vVideo.setVisibility(0);
            ((ActivitySearchNovelResultBinding) this.binding).tvVoiceNovel.setTypeface(Typeface.DEFAULT);
            ((ActivitySearchNovelResultBinding) this.binding).tvNovel.setTextColor(-1);
            ((ActivitySearchNovelResultBinding) this.binding).tvVoiceNovel.setTextColor(Color.parseColor("#b1b1b1"));
            ((ActivitySearchNovelResultBinding) this.binding).vPeople.setVisibility(8);
            if (((ActivitySearchNovelResultBinding) this.binding).viewPager.getCurrentItem() != 0) {
                ((ActivitySearchNovelResultBinding) this.binding).viewPager.setCurrentItem(0);
            }
        } else if (view.getId() == R.id.tv_voice_novel) {
            ((ActivitySearchNovelResultBinding) this.binding).tvNovel.setTypeface(Typeface.DEFAULT);
            ((ActivitySearchNovelResultBinding) this.binding).vVideo.setVisibility(8);
            ((ActivitySearchNovelResultBinding) this.binding).tvVoiceNovel.setTypeface(Typeface.DEFAULT_BOLD);
            ((ActivitySearchNovelResultBinding) this.binding).vPeople.setVisibility(0);
            ((ActivitySearchNovelResultBinding) this.binding).tvVoiceNovel.setTextColor(-1);
            ((ActivitySearchNovelResultBinding) this.binding).tvNovel.setTextColor(Color.parseColor("#b1b1b1"));
            if (((ActivitySearchNovelResultBinding) this.binding).viewPager.getCurrentItem() != 1) {
                ((ActivitySearchNovelResultBinding) this.binding).viewPager.setCurrentItem(1);
            }
        } else if (view.getId() == R.id.tv_cancel) {
            finish();
        } else if (view.getId() == R.id.img_back) {
            finish();
        } else if (view.getId() == R.id.tv_search) {
            finish();
        }
    }

    /* access modifiers changed from: protected */
    @Override // androidx.fragment.app.FragmentActivity
    public void onResume() {
        super.onResume();
        getUserInfo();
    }

    public void getUserInfo() {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().userInfo(), JsonParams.build().commit(), new HttpCallback<BaseRes<UserInfo>>("userInfo") {
            /* class com.grass.p019lv.novel.activity.SearchNovelResultActivity.C31052 */

            public void onLvSuccess(BaseRes<UserInfo> baseRes) {
                if (baseRes.getCode() == 200) {
                    SpUtils.getInstance().setUserInfo(baseRes.getData());
                }
            }
        });
    }

    /* renamed from: com.grass.lv.novel.activity.SearchNovelResultActivity$Adapter */
    class Adapter extends FragmentStatePagerAdapter {
        @Override // androidx.viewpager.widget.PagerAdapter
        public int getCount() {
            return 2;
        }

        private Adapter(FragmentManager fragmentManager, int i) {
            super(fragmentManager, i);
        }

        @Override // androidx.fragment.app.FragmentStatePagerAdapter
        public Fragment getItem(int i) {
            if (i == 0) {
                return SearchNovelResultActivity.this.searchNovelFragment;
            }
            return SearchNovelResultActivity.this.searchVoiceNovelFragment;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getSearchNovelEvent(SearchNovelNumEvent searchNovelNumEvent) {
        TextView textView = ((ActivitySearchNovelResultBinding) this.binding).tvNovel;
        textView.setText("成人小說 " + searchNovelNumEvent.getNum());
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getSearchVoiceNovelEvent(SearchVoiceNovelNumEvent searchVoiceNovelNumEvent) {
        TextView textView = ((ActivitySearchNovelResultBinding) this.binding).tvVoiceNovel;
        textView.setText("有聲讀物 " + searchVoiceNovelNumEvent.getNum());
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivitySearchNovelResultBinding) this.binding).toolbar).init();
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
